# 7.4 EvictInterceptor

The EvictInterceptor can automatically clear the cache based on the CacheName annotation. Here's an example code snippet:

@Before(EvictInterceptor.class)
@CacheName("blogList")
public void update() {
    getModel(Blog.class).update();
    redirect("blog.html");
}
1
2
3
4
5
6

In the above example, the use of EvictInterceptor will clear the cache data with the cacheName set to blogList. The corresponding CacheInterceptor will then automatically update the cache data named blogList.

Starting from version 3.6 of JFinal, the @CacheName annotation supports multiple cacheNames separated by commas. This is convenient for clearing multiple cache names at once. For example:

@Before(EvictInterceptor.class)
@CacheName("blogList, hotBlogList")  // Multiple cacheNames separated by commas
public void update() {
    ...
}
1
2
3
4
5

With this feature, you can easily evict multiple caches with a single annotation, making your cache management strategy more flexible and efficient.

Last Updated: 9/22/2023, 5:04:24 AM